define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'cookie'], function ($, undefined, Backend, Table, Form, Template, undefined) {
    $.cookie.prototype.defaults = { path: Config.moduleurl };
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'subject/subject/index',
                    add_url: 'subject/subject/add',
                    edit_url: 'subject/subject/edit',
                    del_url: 'subject/subject/del',
                    table: 'subject',
                }
            });

            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                sortOrder: 'asc',
                search: false,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), sortable: true },
                        { field: 'title', title: __('Title'), operate: 'LIKE' },
                        { field: 'thumbs_text', title: __('Thumbs'), formatter: Table.api.formatter.image, searchable: false },
                        { field: 'price', title: __('Price') },
                        { field: 'category.name', title: __('CategoryName'),searchList:$.getJSON("subject/subject/category") },
                        { field: 'like_text', title: __('Likes_text'), searchable: false },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: '课程章节',
                                    title: __('课程章节'),
                                    classname: 'btn btn-info btn-xs btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'subject/chapter/index?subid={id}',
                                    extend: 'data-toggle="tooltip" data-container="body"',
                                    refresh: true, //操作完成后是否刷新列表
                                }]
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            setTimeout(function () {
                $("#c-type").trigger("change");
            }, 100);
        },
        edit: function () {
            Controller.api.bindevent();
        },
        del: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
})